package com.alibaba.webx.tutorial1.app1.dao.impl;

import java.util.List;

import org.apache.ecs.xhtml.s;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Service;

import com.alibaba.webx.tutorial1.app1.dao.RoleDAO;
import com.alibaba.webx.tutorial1.app1.vo.Role;

@Service
public class RoleDAOImpl implements RoleDAO {
	
	private SqlSessionTemplate sqlSession;
	
	public SqlSessionTemplate getSqlSession() {
		return sqlSession;
	}

	public void setSqlSession(SqlSessionTemplate sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	@Override
	public int countAll() {
		int i1 = sqlSession.selectOne("p_role_templage.countAll");
		return i1;
	}
	
	@Override
    public Role selectByPrimaryKey(Integer id) {
		Role role = sqlSession.selectOne("p_role_templage.selectByPrimaryKey", id);
		return role;
    }

	@Override
	public int deleteByPrimaryKey(Integer id) throws Exception {
		try {
			Role _key = new Role();
	        _key.setId(id);
	        int rows = sqlSession.delete("p_role_templage.deleteByPrimaryKey", _key);
	        return rows;
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public Integer insert(Role record) throws Exception {
		try {
			int rows = sqlSession.insert("p_role_templage.insert", record);
			return rows;
		} catch (Exception e) {
			throw e;
		}
	}

	@Override
	public int updateByPrimaryKey(Role record) throws Exception {
		try {
			int rows = sqlSession.update("p_role_templage.updateByPrimaryKey", record);
	        return rows;
		} catch (Exception e) {
			throw e;
		}
	}
}